/// @tags: DP on Tree
#include <cstdio>
#include <iostream>

using std::cin;
using std::cout;
using std::min;

namespace BlueQuantum {

typedef long long LL;

constexpr int MAXN = 4e4 + 3, DEP = 41;

int n, m, top, dcnt;
int a[MAXN], b[MAXN], c[MAXN], s[MAXN], t[MAXN], dfn[MAXN], stk[MAXN];
LL f[DEP * 2][DEP][DEP];

void dfs(int u, int x, int y) {
  int p = dfn[u] = top ? stk[top--] : ++dcnt;
  if (!s[u]) {
    for (int i = 0; i <= x; ++i)
      for (int j = 0; j <= y; ++j) f[p][i][j] = (LL)c[u] * (a[u] + i) * (b[u] + j);
    return;
  }
  dfs(s[u], x + 1, y);
  dfs(t[u], x, y + 1);
  int ls = dfn[s[u]], rs = dfn[t[u]];
  for (int i = 0; i <= x; ++i)
    for (int j = 0; j <= y; ++j)
      f[p][i][j] = min(f[ls][i + 1][j] + f[rs][i][j], f[ls][i][j] + f[rs][i][j + 1]);
  stk[++top] = ls, stk[++top] = rs;
}

inline int main() {
  cin >> n;
  m = 2 * n - 1;
  for (int i = 1; i < n; ++i) {
    int u, v;
    cin >> u >> v;
    s[i] = u < 0 ? n - 1 - u : u, t[i] = v < 0 ? n - 1 - v : v;
  }
  for (int i = n; i <= m; ++i) cin >> a[i] >> b[i] >> c[i];
  dfs(1, 0, 0);
  cout << f[dfn[1]][0][0];
  return 0;
}

}  // namespace BlueQuantum

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("/tmp/CodeTmp/testdata.in", "r", stdin);
  freopen("/tmp/CodeTmp/testdata.out", "w", stdout);
#else
  freopen("P4438 [HNOI AHOI2018] 道路.in", "r", stdin);
  freopen("P4438 [HNOI AHOI2018] 道路.out", "w", stdout);
#endif
#endif

  std::ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  return BlueQuantum::main();
}
